$(function(){
	$('.submit1').click(function(){
		$account=$('.account').val();
		$password=$('.password').val();
		if($account==''){
			alert("请输入账号！");
			return false;
		}
	/*	if($password==''){
			alert("请输入密码！");
			return false;
		}*/
	});

	$('.submit2').click(function(){
		$phone=$('.phone').val();
		$password=$('.password').val();
		$pre=/^(13|18|15|17|14)(\d{9})$/;
		if(!$pre.test($phone)){
			alert("请输入正确格式的手机号！");
			return false;
		}
		if($password==''){
			alert("请输入密码！");
			return false;
		}
	})
	$(".tiyan,.expressa").click(function(event){
		event.stopPropagation();
	});

	$(document).click(function(e){
		var target  = $(e.target);
		if(target.closest(".bottonm").length == 0){
			$(".bottom").hide();
		}
	}) 
	$(".express_info").click(function(e){
		$(".express_info").hide();
	});

	$('.apply').click(function(){
		$(".apply").hide();
	})
})
function official(){
	$wechat=$('.wechat').val();
	$phone=$('.phone').val();
	$name=$('.name').val();
	$address=$('.address').val();
	$pre=/^(13|18|15|17|14)(\d{9})$/;
	if($wechat==''){
		alert("请输入微信号");
		return false;
	}
	if(!$pre.test($phone)){
		alert("请输入正确格式的手机号");
		return false;
	}
	if($name==''){
		alert("请输入姓名");
		return false;
	}
	if($address==''){
		alert("请输入送货地址");
		return false;
	}
	$('#form').ajaxSubmit({
		type: 'post', 
		url: 'index.php?m=admin&c=Info&a=official',
		success: function(data) {  
		  alert(data);
/*		   if(data!='更新成功')
		   {
			$('#form').resetForm(); 
		   }*/
			
		}

	});
	return false; 
}

function agent(){
	$wechat=$('.wechat').val();
	$phone=$('.phone').val();
	$name=$('.name').val();
	$address=$('.address').val();
	$pre=/^(13|18|15|17|14)(\d{9})$/;
	if($wechat==''){
		alert("请输入微信号");
		return false;
	}
	if(!$pre.test($phone)){
		alert("请输入正确格式的手机号");
		return false;
	}
	if($name==''){
		alert("请输入姓名");
		return false;
	}
	if($address==''){
		alert("请输入送货地址");
		return false;
	}
	$('#form').ajaxSubmit({
		type: 'post', 
		url: 'index.php?m=Home&c=Index&a=shouquan',
		success: function(data) { 
			alert(data);
			$('#form').resetForm(); 
		}

	});
	return false; 
}

function agent1(){
	$wechat=$('.wechat').val();
	$phone=$('.phone').val();
	$name=$('.name').val();
	$address=$('.address').val();
	$pre=/^(13|18|15|17|14)(\d{9})$/;
	if($wechat==''){
		alert("请输入微信号");
		return false;
	}
	if(!$pre.test($phone)){
		alert("请输入正确格式的手机号");
		return false;
	}
	if($name==''){
		alert("请输入姓名");
		return false;
	}
	if($address==''){
		alert("请输入送货地址");
		return false;
	}
	$('#form').ajaxSubmit({
		type: 'post', 
		url: 'index.php?m=admin&c=Info&a=agent',
		success: function(data) { 
			alert(data);
			/*$('#form').resetForm();*/ 
		}

	});
	return false; 
}


function change(){
	$action="index.php?m=admin&c=Index&a=zoon";
	$.post($action,function(data){
		$(".info").html(data);
	})
}

function change1(){
	$action="index.php?m=Home&c=Index&a=normal";
	$.post($action,function(data){
		$(".info").html(data);
	})
}


function zoon1(){
	$wechat=$('.wechat').val();
	$phone=$('.phone').val();
	$name=$('.name').val();
	$address=$('.address').val();
	$time=$('.time').val();
	$pre=/^(13|18|15|17|14)(\d{9})$/;
	if($wechat==''){
		alert("请输入微信号");
		return false;
	}
	if(!$pre.test($phone)){
		alert("请输入正确格式的手机号");
		return false;
	}
	if($name==''){
		alert("请输入姓名");
		return false;
	}
	if($address==''){
		alert("请输入送货地址");
		return false;
	}
	if($time==''||$time<6||$time>48){
		alert("请输入6-48个月正确授权有效期");
		return false;
	}
	$('#form1').ajaxSubmit({
		type: 'post', 
		url: 'index.php?m=admin&c=Info&a=zoon1',
		success: function(data) { 
			alert(data);
			$('#form1').resetForm(); 
		}

	});
	return false; 
}

function normal(){
	$wechat=$('.wechat').val();
	$phone=$('.phone').val();
	$name=$('.name').val();
	$address=$('.address').val();
	$pre=/^(13|18|15|17|14)(\d{9})$/;
	if($wechat==''){
		alert("请输入微信号");
		return false;
	}
	if(!$pre.test($phone)){
		alert("请输入正确格式的手机号");
		return false;
	}
	if($name==''){
		alert("请输入姓名");
		return false;
	}
	if($address==''){
		alert("请输入送货地址");
		return false;
	}
	$('#form1').ajaxSubmit({
		type: 'post', 
		url: 'index.php?m=Home&c=Index&a=normal1',
		success: function(data) { 
			alert(data);
			$('#form1').resetForm(); 
		}

	});
	return false; 
}


function normal1(){
	$wechat=$('.wechat').val();
	$phone=$('.phone').val();
	$name=$('.name').val();
	$address=$('.address').val();
	$pre=/^(13|18|15|17|14)(\d{9})$/;
	if($wechat==''){
		alert("请输入微信号");
		return false;
	}
	if(!$pre.test($phone)){
		alert("请输入正确格式的手机号");
		return false;
	}
	if($name==''){
		alert("请输入姓名");
		return false;
	}
	if($address==''){
		alert("请输入送货地址");
		return false;
	}
	$('#form1').ajaxSubmit({
		type: 'post', 
		url: 'index.php?m=admin&c=Info&a=normal',
		success: function(data) { 
			alert(data);
			/*$('#form1').resetForm(); */
		}

	});
	return false; 
}

function update_relative_js(){
	$wechat=$('.wechat').val();
	$phone=$('.phone').val();
	$name=$('.name').val();
	$address=$('.address').val();
	$pre=/^(13|18|15|17|14)(\d{9})$/;
	if($wechat==''){
		alert("请输入微信号");
		return false;
	}
	if(!$pre.test($phone)){
		alert("请输入正确格式的手机号");
		return false;
	}
	if($name==''){
		alert("请输入姓名");
		return false;
	}
	if($address==''){
		alert("请输入送货地址");
		return false;
	}
	

	$('#form1').ajaxSubmit({
		type: 'post', 
		url: 'index.php?m=admin&c=Relative&a=update_relative',
		success: function(data) { 
			alert(data);
			$('#cs_data').html(data);
			/*$('#form1').resetForm(); */
		}

	});
	return false; 
}
function add_address(){
	$address=$('.address').val();
	$name=$('.name').val();
	$phone=$('.phone').val();
	$number=$('.number').val();
	$pre=/^(13|18|15|17|14)(\d{9})$/;
	$pre1=/^(\d*)$/;
	if($address==''){
		alert("请输入正确的收货地址！");
		return false;
	}
	if($name==''){
		alert("请输入收货人姓名！");
		return false;
	}
	if(!$pre.test($phone)){
		alert("请输入正确格式的手机号！");
		return false;
	}
	if(!$pre1.test($number)||$number<1){
		alert("请输入正确的数量！");
		return false;
	}
}

function user_add_shouquan(){
	$address=$('.address').val();
	$name=$('.name').val();
	$phone=$('.phone').val();
	$wechat=$('.wechat').val();
	$pre=/^(13|18|15|17|14)(\d{9})$/;
	$pre1=/^(\d*)$/;
	if($address==''){
		alert("请输入正确的收货地址！");
		return false;
	}
	if($name==''){
		alert("请输入姓名！");
		return false;
	}
	if(!$pre.test($phone)){
		alert("请输入正确格式的手机号！");
		return false;
	}
	if($wechat){
		alert("请输入微信号！");
		return false;
	}
}

function delete1(pk){//删除订单地址
	if(confirm('是否删除？')) {
		location.href="index.php?m=Home&c=Info&a=delete&pk="+pk;
	}
}


function delete2(pk){//删除活动
	if(confirm('是否删除？')) {
		location.href="index.php?m=admin&c=Info&a=delete&pk="+pk;
	}
}

function delete3(pk){//删除授权 
	if(confirm('是否删除？')) {
		location.href="index.php?m=admin&c=Info&a=sdelete&user_id="+pk;
	}
}
function frozen(obj,user_id,is_frozen){//删除授权
var msg='';
if(is_frozen==1)msg="是否冻结?";
else msg="是否解冻?";
 
	if(confirm(msg)) {
		$action='index.php?m=admin&c=Info&a=frozen_users';
		$.post($action,{user_id:user_id,is_frozen:is_frozen},function(data){
			alert(data);
			if(is_frozen==1)
			$(obj).parent().html('<a  href="javascript:void(0)" onclick="frozen(this,'+user_id+',0) ">解冻</a>   ');
			else
			$(obj).parent().html('<a  href="javascript:void(0)" onclick="frozen(this,'+user_id+',1) ">冻结</a>   ');
		})
	}
}
function change_shouquan(obj,user_id,tp){//删除授权
var msg='';
if(tp==1)msg="是否升级?";
else msg="是否降级?";
 
	if(confirm(msg)) {
		$action='index.php?m=admin&c=Relative&a=change_shouquan';
		$.post($action,{user_id:user_id,tp:tp},function(data){
			alert(data.mes);
			if(data.errcode<1)
			{
				var p_obj=$(obj).parent().parent().find('.change_shouquan');
				var level=Number(p_obj.html());
				
				if(tp==1){level=level-1;}
				else
				{level=level+1;}
				p_obj.html(level);
			}
			

			
		})
	}
}

function delete4(pk){//确认授权 
	if(confirm('是否删除？')) {
		$action='index.php?m=admin&c=Info&a=sqdelete';
		$.post($action,{user_id:pk},function(data){
			alert(data);
			location.href="index.php?m=admin&c=Info&a=check";
		})
	}
}

function check1(pk){//确认授权 
	if(confirm('是否授权？')) {
		$action='index.php?m=admin&c=Info&a=check1';
		$.post($action,{user_id:pk},function(data){
			alert(data);
			location.href="index.php?m=admin&c=Info&a=check";
		})
	}
}
function express(pk){
	$action='index.php?m=Home&c=Index&a=express';
	$.post($action,{pk:pk},function(data){
		$('.express_info').show();
		$('.express').html("快递公司:"+data.express);
		$('.expressid').html("快递单号:"+data.expressid);
	})
}

function selectAll(){
	var a = document.getElementsByTagName("input");
	if(a[0].checked){
		for(var i = 0;i<a.length;i++){
			if(a[i].type == "checkbox") a[i].checked = false;
		}
	}
	else{
		for(var i = 0;i<a.length;i++){
			if(a[i].type == "checkbox") a[i].checked = true;
		}
	}
	return false;
}

function slideup(){
	$(".bottom").slideToggle();
}

function canel(){
	$(".bottom").slideToggle();
}

/*function activity(obj){
	obj.siblings().children('.shouquan').css({"color":"#393C3F","border-bottom":"1px solid #fff"});
	obj.children('.shouquan').css({"color":"#931D22","height":"59px","border-bottom":"1px solid #931D22"});
	$action='index.php?m=Home&c=Info&a=activity';
	$.post($action,function(data){
		$('#info').html(data);
	})
}*/

function pay(obj){
	obj.siblings().children('.shouquan').css({"color":"#393C3F","border-bottom":"1px solid #fff"});
	obj.children('.shouquan').css({"color":"#931D22","height":"57px","border-bottom":"3px solid #931D22"});
	$action='index.php?m=Home&c=Info&a=pay';
	$.post($action,function(data){
		$('#info').html(data);
	})
}

function add(obj){
	obj.siblings().children('.shouquan').css({"color":"#393C3F","border-bottom":"1px solid #fff"});
	obj.children('.shouquan').css({"color":"#931D22","height":"57px","border-bottom":"3px solid #931D22"});
	$action='index.php?m=Home&c=Info&a=trial';
	$.get($action,function(data){
		$('#info').html(data);
	})
}

function exportep(){
	$('#info').html("<form action='index.php?m=Admin&c=Index&a=impuser' method='post' enctype='multipart/form-data'><input type='file' name='mport'/><input type='hidden' name='table' value='tablename'/><input type='submit' value='导入'/></form>");
}

function tijiao(pk){
	if(pk==0){
		return false;
	}
}

function show1(){
	$('.apply').show();
}

function tpay(pk){
	if(confirm('确认付款？')) {
		$action='index.php?m=admin&c=Info&a=queren';
		$.post($action,{pk:pk},function(data){
			location.href="index.php?m=admin&c=Info&a=list1";
		});
	}
}